from fastapi import FastAPI
import uvicorn
from pydantic import BaseModel
app = FastAPI()
class Numbers(BaseModel):
    a: float
    b: float
# 修改为同时支持JSON body和查询参数
@app.post("/square_sum")
async def calculate_squares(nums: Numbers):
    """计算两个数的平方和"""
    return {
        "a_squared": nums.a ** 2,
        "b_squared": nums.b ** 2,
        "sum": nums.a**2 + nums.b**2
    }

@app.get("/resources/greeting/{name}")
async def get_greeting(name: str):
    """问候接口"""
    return {"result": f"Hello, {name}!"}

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)